package exercise;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Scanner;

/*
e.模拟实现一个记录手机视频时长  每次视频10分钟   第二次累加上一次的时间
   结果如下: 通话时长    "10:15:12";
比如: 开始通话
         已经通过: 00:10:00
         是否继续通话(y/n): y
         已经通过: 00:20:00
         是否继续通话(y/n): n
         通话时才: 00:20:00
 */
public class ex5 {
    public static void main(String[] args) throws ParseException {
        //useDate();
        useLocalTime();
String a="10:15:12";
//a.concat()
    }

    private static void useLocalTime() {
        System.out.println("开始通话");
        LocalTime min = LocalTime.MIN;//00:00
        LocalTime max = LocalTime.MAX;//23:59:59.999999999
        LocalTime time = LocalTime.of(0, 0, 0);
        System.out.println("已经通过：" + time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        Scanner sc = new Scanner(System.in);

        while (true) {
            System.out.println("是否继续通话(y/n):");
            String str = sc.next();

            if ("Y".equals(str) || "y".equals(str)) {
                //增加10分钟
//                time = time.withMinute(10);
                time = time.plusMinutes(10);
                System.out.println("已经通过：" + time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
            }
            //通话结束
            else if ("N".equals(str) || "n".equals(str)) break;
            else System.out.println("输入有误，请输入y/n");

        }
        System.out.println("通话时长：" + time.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
    }

    private static void useDate() throws ParseException {
        System.out.println("开始通话");
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        Date time = sdf.parse("00:00:00");
        System.out.println("已经通过：" + sdf.format(time));

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("是否继续通话(y/n):");
            String str = sc.next();

            if ("Y".equals(str) || "y".equals(str)) {
                time.setTime(time.getTime() + 10 * 60 * 1000);
                System.out.println("已经通过：" + sdf.format(time));
            } else if ("N".equals(str) || "n".equals(str))
                break;
            else System.out.println("输入有误，请输入y/n");

        }
        System.out.println("通话时长：" + sdf.format(time));
    }
}
